package com.refusea.train.mapper

import com.refusea.train.domain.entity.Classroom
import org.apache.ibatis.annotations.Delete
import org.apache.ibatis.annotations.Insert
import org.apache.ibatis.annotations.Mapper
import org.apache.ibatis.annotations.Options
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import org.apache.ibatis.annotations.Update

@Mapper
interface ClassroomMapper {

    @Insert("INSERT INTO classroom (school_id, name, capacity) VALUES (#{schoolId}, #{name}, #{capacity})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    fun insert(classroom: Classroom): Int

    @Delete("DELETE FROM classroom WHERE id=#{id} && school_id=#{schoolId}")
    fun delete(@Param("id") id: Int, @Param("schoolId") schoolId: Int): Int

    @Update("UPDATE classroom SET name=#{name}, capacity=#{capacity} WHERE id=#{id}")
    fun update(classroom: Classroom): Int

    @Select("SELECT * FROM classroom WHERE id = #{id}")
    fun select(id: Int): Classroom?

    @Select("SELECT * FROM classroom where school_id = #{schoolId}")
    fun list(schoolId: Int): List<Classroom>

    @Select("SELECT * FROM classroom")
    fun listAll(): List<Classroom>
}
